/***
 * @file: 请求方式封装
 * @author: xiaoyu
 * @Date: 2021-07-07 15:40:11
 */
import axios from './axios'
import Qs from 'qs'

const httpService = {
  async get(api: string, params?: any) {
    let queryStr = params
    if (typeof params === 'object') {
      queryStr = Qs.stringify(params)
    }
    return await axios.get(`${api}?${queryStr}`)
  },

  // post：application/x-www-form-urlencoded;charset=UTF-8
  async post(api: string, params?: any) {
    return await axios.post(api, params, {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
      }
    })
  },

  async postJson(api: string, params?: any) {
    return await axios.post(api, params, {
      headers: {
        'Content-Type': 'application/json;charset=UTF-8'
      }
    })
  },

  postFile() {}
}

export default httpService
